#!/bin/sh

#%Module
#% description: Displays GRASS vector data in the active frame on the graphics monitor.
#% keywords: display
#%End
#%Flag
#% key: v
#% description: Run verbosely
#%End
#%Flag
#% key: a
#% description: Get colors from map table column (of form RRR:GGG:BBB)
#% guisection: Colors
#%End
#%Flag
#% key: c
#% description: Random colors according to category number (or layer number if 'layer=-1' is given)
#% guisection: Colors
#%End
#%Flag
#% key: i
#% description: Use values from 'cats' option as line ID
#% guisection: Query
#%End
#%Flag
#% key: x
#% description: Don't add to list of vectors and commands in monitor (it won't be drawn if the monitor is refreshed)
#%End
#%Option
#% key: map
#% type: string
#% required: yes
#% multiple: no
#% key_desc: name
#% description: Name of input vector map
#% gisprompt: old,vector,vector
#%End
#%Option
#% key: type
#% type: string
#% required: no
#% multiple: yes
#% options: point,line,boundary,centroid,area,face
#% label: Type
#% description: Feature type(s)
#% answer: point,line,boundary,centroid,area,face
#%End
#%Option
#% key: display
#% type: string
#% required: no
#% multiple: yes
#% options: shape,cat,topo,dir,attr,zcoor
#% description: Display
#% answer: shape
#%End
#%Option
#% key: attrcol
#% type: string
#% required: no
#% multiple: no
#% description: Name of column to be displayed
#% guisection: Labels
#%End
#%Option
#% key: icon
#% type: string
#% required: no
#% multiple: no
#% options: demo/muchomurka,demo/smrk,basic/arrow1,basic/arrow2,basic/box,basic/circle,basic/cross1,basic/cross2,basic/diamond,basic/marker,basic/octagon,basic/point,basic/pushpin,basic/star,basic/triangle,basic/x,extra/4pt_star,extra/adcp,extra/airport,extra/alpha_flag,extra/bridge,extra/compass,extra/dive_flag,extra/fancy_compass,extra/half-circle,extra/offbox_ne,extra/offbox_nw,extra/offbox_se,extra/offbox_sw,extra/pentagon,extra/target
#% description: Point and centroid symbol
#% answer: basic/x
#% guisection: Symbols
#%End
#%Option
#% key: size
#% type: integer
#% required: no
#% multiple: no
#% description: Symbol size
#% answer: 8
#% guisection: Symbols
#%End
#%Option
#% key: layer
#% type: integer
#% required: no
#% multiple: no
#% label: Layer number
#% description: Layer number. If -1, all layers are displayed.
#% answer: 1
#%End
#%Option
#% key: cats
#% type: string
#% required: no
#% multiple: no
#% key_desc: range
#% label: Category values
#% description: Example: 1,3,7-9,13
#% guisection: Query
#%End
#%Option
#% key: where
#% type: string
#% required: no
#% multiple: no
#% key_desc: sql_query
#% label: WHERE conditions of SQL statement without 'where' keyword.
#% description: Example: income < 1000 and inhab >= 10000
#% guisection: Query
#%End
#%Option
#% key: width
#% type: integer
#% required: no
#% multiple: no
#% description: Line width
#% answer: 0
#% guisection: Lines
#%End
#%Option
#% key: wcolumn
#% type: string
#% required: no
#% multiple: no
#% description: Name of column for line widths (these values will be scaled by wscale)
#% guisection: Lines
#%End
#%Option
#% key: wscale
#% type: double
#% required: no
#% multiple: no
#% description: Scale factor for wcolumn
#% answer: 1
#% guisection: Lines
#%End
#%Option
#% key: color
#% type: string
#% required: no
#% multiple: no
#% description: Line color
#% answer: black
#% gisprompt: color,grass,color
#% guisection: Colors
#%End
#%Option
#% key: fcolor
#% type: string
#% required: no
#% multiple: no
#% description: Area fill color
#% answer: 200:200:200
#% gisprompt: color,grass,color
#% guisection: Colors
#%End
#%Option
#% key: rgb_column
#% type: string
#% required: no
#% multiple: no
#% description: Name of color definition column (for use with -a flag)
#% answer: GRASSRGB
#% guisection: Colors
#%End
#%Option
#% key: llayer
#% type: integer
#% required: no
#% multiple: no
#% description: Layer for labels (default: the given layer number)
#% guisection: Labels
#%End
#%Option
#% key: lcolor
#% type: string
#% required: no
#% multiple: no
#% description: Label color
#% answer: red
#% gisprompt: color,grass,color
#% guisection: Labels
#%End
#%Option
#% key: bgcolor
#% type: string
#% required: no
#% multiple: no
#% description: Label background color
#% answer: none
#% gisprompt: color,grass,color
#% guisection: Labels
#%End
#%Option
#% key: bcolor
#% type: string
#% required: no
#% multiple: no
#% description: Label border color
#% answer: none
#% gisprompt: color,grass,color
#% guisection: Labels
#%End
#%Option
#% key: lsize
#% type: integer
#% required: no
#% multiple: no
#% description: Label size (pixels)
#% answer: 8
#% guisection: Labels
#%End
#%Option
#% key: font
#% type: string
#% required: no
#% multiple: no
#% description: Font name
#% guisection: Labels
#%End
#%Option
#% key: xref
#% type: string
#% required: no
#% multiple: no
#% options: left,center,right
#% description: Label horizontal justification
#% answer: left
#% guisection: Labels
#%End
#%Option
#% key: yref
#% type: string
#% required: no
#% multiple: no
#% options: top,center,bottom
#% description: Label vertical justification
#% answer: center
#% guisection: Labels
#%End
#%Option
#% key: minreg
#% type: double
#% required: no
#% multiple: no
#% description: Minimum region size (average from height and width) when map is displayed
#%End
#%Option
#% key: maxreg
#% type: double
#% required: no
#% multiple: no
#% description: Maximum region size (average from height and width) when map is displayed
#%End
#%Option
#% key: render
#% type: string
#% required: no
#% multiple: no
#% options: g,r,d,c
#% description: Rendering method for filled polygons
#% answer: g
#%End


if [ -z "$GISBASE" ] ; then
    echo "You must be in GRASS GIS to run this program." 1>&2
    exit 1
fi

if [ "$1" != "@ARGS_PARSED@" ] ; then
    exec g.parser "$0" "$@"
fi

# CODE GOES HERE

cmdfile="`g.gisenv get=GRASS_PYCMDFILE`"

if [ -e ${cmdfile} ] && [ -n "${cmdfile}" ]; then
    echo -n
else
    echo "WARNING: GRASS_PYCMDFILE File not existing. Run p.mon" >&2
    exit 1
fi


eval "`echo ${GIS_OPT_MAP}| sed -e 's/^/NAME=/' -e 's/@/; MAPSET=/'`;"

#echo $NAME 

if [ -z "${MAPSET}" ]; then
    mapset=""
else
    mapset="mapset=${MAPSET}"
fi

#echo $MAPSET

eval "`g.findfile element=vector file=${NAME} ${mapset}`"

#echo $NAME 
#echo $MAPSET

if [ -z "${GIS_OPT_CATLIST}" ]; then
    CATLIST="None"
else
    CATLIST="${GIS_OPT_CATLIST}"
fi

if [ -z "${GIS_OPT_VALLIST}" ]; then
    VALLIST="None"
else
    VALLIST="${GIS_OPT_VALLIST}"
fi

if [ -z "${GIS_OPT_OPACITY}" ]; then
    OPACITY="100"
else
    OPACITY="${GIS_OPT_OPACITY}"
fi

if [ "${GIS_FLAG_c}" -eq "1" ]; then
    CATSCOLORS="True"
else
    CATSCOLORS="False"
fi


#cmd="self.map.AddRasterLayer(self, $NAME $MAPSET $CATLIST $VALLIST $INVERCATS $INVERT $OPACITY)"

cmd="addvector ${name} ${mapset}"
echo ${cmd} >>${cmdfile}
